// pages/list/list.js
const http = require("../../utils/http")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        seasonArr: [],

        endtype: false //false 没到底 ,true 到底了
    },
    customData: {
        page:1, //当前页
    },
    getData() {
        http.request("requirement/request/getMatchedProducts", {
            curPagePath: "/wx/customer/classic/search.html?pageid=0piQDrywbusu9y3CXGJj",
            keyWord: "中国",
            pageNow: this.customData.page,
            pageSize: 10,
            product_type: 1
        }, "post").then(res => {
            console.log(res);
            this.setData({
                seasonArr: res.data.matchedProducts
            })
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getData();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.getData();
        wx.stopPullDownRefresh();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (!this.data.endtype) {
            //this.setData({page:this.data.page+1});
            this.customData.page++;
            http.request("requirement/request/getMatchedProducts", {
                curPagePath: "/wx/customer/classic/search.html?pageid=0piQDrywbusu9y3CXGJj",
                keyWord: "中国",
                pageNow: this.customData.page,
                pageSize: 10,
                product_type: 1
            }, "post").then(res => {
                console.log(res);
                const data = res.data.matchedProducts;
                if (data.length == 0) {
                    this.setData({
                        endtype: true
                    })
                } else {
                    //4.将新数据追加到原数据的后面
                    const oldData = this.data.seasonArr;
                    const newData = oldData.concat(data);
                    this.setData({
                        seasonArr: newData
                    })
                }
            })
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})